﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace FwProject.Migrations.FwProjectAppShopDb
{
    public partial class Drop_ShopOrderCoupon_To_appshop : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "shop_order_coupon");

            migrationBuilder.AlterColumn<DateTime>(
                name: "DeliveryTime",
                table: "shop_order_details",
                nullable: true,
                oldClrType: typeof(DateTime));

            migrationBuilder.AddColumn<string>(
                name: "ReturngoodsContetn",
                table: "shop_order_details",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "ReturngoodsPrice",
                table: "shop_order_details",
                nullable: false,
                defaultValue: 0m);

            migrationBuilder.AddColumn<string>(
                name: "refundNo",
                table: "shop_order_details",
                nullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "ReceivingAddress",
                table: "shop_order",
                maxLength: 200,
                nullable: false,
                oldClrType: typeof(string),
                oldMaxLength: 200);

            migrationBuilder.AddColumn<string>(
                name: "alipayTradeNo",
                table: "shop_order",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_shop_order_ReceivingAddress",
                table: "shop_order",
                column: "ReceivingAddress");

            migrationBuilder.AddForeignKey(
                name: "FK_shop_order_shop_receiving_address_ReceivingAddress",
                table: "shop_order",
                column: "ReceivingAddress",
                principalTable: "shop_receiving_address",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_shop_order_shop_receiving_address_ReceivingAddress",
                table: "shop_order");

            migrationBuilder.DropIndex(
                name: "IX_shop_order_ReceivingAddress",
                table: "shop_order");

            migrationBuilder.DropColumn(
                name: "ReturngoodsContetn",
                table: "shop_order_details");

            migrationBuilder.DropColumn(
                name: "ReturngoodsPrice",
                table: "shop_order_details");

            migrationBuilder.DropColumn(
                name: "refundNo",
                table: "shop_order_details");

            migrationBuilder.DropColumn(
                name: "alipayTradeNo",
                table: "shop_order");

            migrationBuilder.AlterColumn<DateTime>(
                name: "DeliveryTime",
                table: "shop_order_details",
                nullable: false,
                oldClrType: typeof(DateTime),
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "ReceivingAddress",
                table: "shop_order",
                maxLength: 200,
                nullable: false,
                oldClrType: typeof(Guid),
                oldMaxLength: 200);

            migrationBuilder.CreateTable(
                name: "shop_order_coupon",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    OrderId = table.Column<Guid>(nullable: false),
                    OrderNumber = table.Column<string>(nullable: true),
                    ShopCouponId = table.Column<Guid>(nullable: false),
                    ShopUserCouponId = table.Column<int>(nullable: false),
                    UserId = table.Column<long>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_shop_order_coupon", x => x.Id);
                    table.ForeignKey(
                        name: "FK_shop_order_coupon_shop_order_OrderId",
                        column: x => x.OrderId,
                        principalTable: "shop_order",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_shop_order_coupon_shop_coupon_ShopCouponId",
                        column: x => x.ShopCouponId,
                        principalTable: "shop_coupon",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_shop_order_coupon_OrderId",
                table: "shop_order_coupon",
                column: "OrderId");

            migrationBuilder.CreateIndex(
                name: "IX_shop_order_coupon_ShopCouponId",
                table: "shop_order_coupon",
                column: "ShopCouponId");
        }
    }
}
